from Common import sql_content

class getRule(object):
    def __init__(self):
        self.sql_content = sql_content.sql_content()
    def getAlltopic(self):
        topic = []
        con = self.sql_content.conten()
        sql_topic = "select COLUMN_NAME from information_schema.COLUMNS where table_name ='setrule'"
        cursor = con.cursor()
        try:
            cursor.execute(sql_topic)
            rs = cursor.fetchall()
            for row in rs:
                list_row = list(row)  # 变成列表
                topic.append(list_row)
        except Exception as e:
            print(e)
            con.rollback()
        cursor.close()
        con.close()
        return topic
    def setOnerule(self,data):
        con = self.sql_content.conten()
        cursor = con.cursor()
        sql_insert = "update setrule set " \
                     "web_Name = '%s', entrance_URL= '%s' ,execute_Script = '%s', storage_Table= '%s' , time_Week= '%s' , time_Day_start= '%s' , time_Day_end= '%s' , " \
                     "set_Time= '%s' , limit_Type= '%s' , limit_Value= '%s' , remark= '%s'" \
                     % (data['web_Name'], data['entrance_URL'], data['execute_Script'], data['storage_Table'], data['time_Week'],
                        data['time_Day_start'], data['time_Day_end'],data['set_Time'], data['limit_Type'],
                        data['limit_Value'], data['remark'])
        try:
            cursor.execute(sql_insert)
            con.commit()
            print(cursor.rowcount)
        except Exception as e:
            print(e)
            # 回滚
            con.rollback()
        cursor.close()
        con.close()
if __name__ == "__main__":
    getRule().getAllrule()